package com.xsd.awen.utils;

public class Strings {

    public static final String EMPTY = "";

    public static final String EMPTY_VALUE = "-1";

    public static boolean isEmpty(String value){
        return (value == null || value.trim().length()==0);
    }

    public static boolean isNotEmpty(String value){
        return !isEmpty(value);
    }

    public static boolean equals(String value1,String value2){
        if( value1 == null && value2 == null ){
            return true;
        }
        value1 = value1 == null ? "" : value1;
        value2 = value2 == null ? "" : value2;
        return value1.equals(value2);
    }

    public static boolean isEmpty(Object value){
        if( value == null )return true;
        return value.toString().trim().length()==0;
    }

    public static String firstUp(String value){
        return  Character.toUpperCase(value.charAt(0)) + value.substring(1);
    }

    public static String firstLow(String value){
        return  Character.toLowerCase(value.charAt(0)) + value.substring(1);
    }

    public static String toHump(String value){
        String[] values = value.split("_");
        String rs = "";
        for (int i=0 ; i<values.length ; i++){
            rs += firstUp(values[i]);
        }
        return firstLow(rs);
    }

    public static String toUnderline(String value){
        String result = "";
        char[] values =  value.toCharArray();

        for( int i=0 ; i<values.length ; i++ ){
            char val = values[i];
            if( Character.isUpperCase(val) ){
                result += "_"+Character.toLowerCase(val);
            }else{
                result += val;
            }
        }
        return result;
    }


    public static String getColName(String itemType,String itemId){
        return itemType + "_" + itemId;
    }

}
